package ru.gerunn.silent.trash;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class XClientFrame extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;

	public XClientFrame() {
		initComponents();
	}

	private void initComponents() {

		recieveTextArea = new javax.swing.JTextArea();
		recieveTextArea.setLineWrap(true);
		recieveTextArea.setWrapStyleWord(true);
		recieveTextArea.setEditable(false);

		sendTextArea = new javax.swing.JTextArea();
		sendTextArea.setLineWrap(true);
		sendTextArea.setWrapStyleWord(true);
		sendTextArea.addKeyListener(new KeyListener() {

			public void keyTyped(KeyEvent event) {
			}

			public void keyReleased(KeyEvent event) {
			}

			public void keyPressed(KeyEvent event) {
				if (event.isControlDown()) {
					if (event.getKeyCode() == 10) {
						sendMessage();
					}
				}
			}
		});

		sendButton = new javax.swing.JButton();
		sendButton.setText("send");
		sendButton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent event) {
				sendMessage();
			}

		});

		javax.swing.JScrollPane recieveJScrollPane = new javax.swing.JScrollPane(recieveTextArea);
		javax.swing.JScrollPane sendJScrollPane = new javax.swing.JScrollPane(sendTextArea);

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);

		layout.setHorizontalGroup(
			layout.createSequentialGroup()
				.addGroup(
					layout.createParallelGroup()
						.addComponent(recieveJScrollPane)
						.addComponent(sendJScrollPane)
						.addComponent(sendButton)
				)
			);

		layout.setVerticalGroup(
			layout.createSequentialGroup()
				.addGroup(
					layout.createParallelGroup()
						.addComponent(recieveJScrollPane)
				)
				.addGroup(
					layout.createParallelGroup()
						.addComponent(sendJScrollPane)
				)
				.addGroup(
					layout.createParallelGroup()
						.addComponent(sendButton)
				)
			);

		pack();

	}

	private javax.swing.JTextArea recieveTextArea;
	private javax.swing.JTextArea sendTextArea;
	private javax.swing.JButton sendButton;

	private void sendMessage() {
		recieveTextArea.setText(recieveTextArea.getText() + sendTextArea.getText() + "\r\n");
		sendTextArea.setText("");
	}

	public static void main(String[] args) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				XClientFrame frame = new XClientFrame();
				frame.setSize(500, 500);
				frame.setVisible(true);
			}

		});
	}
}
